﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ChBusiness;
using ChBusiness.User;

using Common;
using ChBusiness.InterfaceClass;

public partial class UserManage_ModifyPWD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
            Session["DangQianRenWu"] = "修改密码";
        }
    }

    private void BindData()
    {       
        this.txtUserID.Text = Session["UserId"].ToString();
        this.txtUserID.Enabled = false;
    }

    protected void btnModify_Clicked(object sender, EventArgs e)
    {
        UserHandle antuUser = new UserHandle();
        if (Encode.Md5(this.txtOldPWD.Text) != (antuUser.GetPWDByUserID(txtUserID.Text)))
        {
            WindowAppear.WriteAlert(Page, "输入的原始密码不正确");
            return;
        }
        if (this.txtNewPWD.Text != this.txtConfirmPWD.Text)
        {
            WindowAppear.WriteAlert(Page, "输入的新密码不一致");
            return;
        }
        if (antuUser.ModifyPWD(this.txtUserID.Text, txtNewPWD.Text))
        {
            //获取用户信息 addby zhongjian 20100303
            DataTable dtTemp = UserHandle.GetUser(Session["UserId"].ToString());
            if (dtTemp.Rows.Count > 0)
            {
                ViewState["Sync_Type"] = dtTemp.Rows[0]["sync_type"].ToString();//数据交换类型(2:地信中心数据)
                ViewState["strID"] = dtTemp.Rows[0]["id"].ToString();//主键ID
                //当是地信中心数据时才更新 
                if (ViewState["Sync_Type"].ToString() == "2")
                {
                    DXInterfaceUserUpdate(ViewState["strID"].ToString());
                }
            }
            WindowAppear.WriteAlert(Page, "修改密码成功");
        }
    }

    /// <summary>
    /// 更新接口用户信息
    /// </summary>
    /// <!--update by zhongjian 20100302-->
    protected void DXInterfaceUserUpdate(string strID)
    {
        string strExMsg = string.Empty;
        string strXml = string.Empty;
        DXCenterClass infaceOperation = new DXCenterClass();

        try
        {
            //获取用户信息,并生成XML内容.
            strXml = infaceOperation.GetUserInfoXml(strID, "update");
            if (!string.IsNullOrEmpty(strXml))
            {
                DxInterface.IdsService idsTemp = new DxInterface.IdsService();
                string strCheckCode = Common.Encode.Md5(DateTime.Now.ToShortDateString());
                //更新用户信息 
                string strReturn = idsTemp.UserInfo(strXml, strCheckCode);

                if (!string.IsNullOrEmpty(strReturn))
                {
                    Common.XmlHandle xhTemp = new Common.XmlHandle();
                    if (!xhTemp.HaveTargetString(strReturn, "UserInfoResponse", "true"))
                    {
                        strExMsg = "更新地信用户密码失败!";

                    }
                    else
                    {
                        strExMsg = "更新地信用户密码成功!";
                    }
                }
                else
                {
                    strExMsg = "更新地信用户密码时接口返回值为空!";
                }
            }
        }
        catch (Exception ex)
        {
            strExMsg = ex.ToString();
        }
        finally
        {
            if (!string.IsNullOrEmpty(strXml))
                infaceOperation.UpdateExceptionAndXml(strXml, strExMsg, 10);
        }
    }
}
